package com.warm.pump.module.skd.controller;


import com.warm.pump.frame.gen.bean.PageBean;
import com.warm.pump.frame.gen.util.MyBeanUtils;
import com.warm.pump.frame.gen.util.OutJson;
import com.warm.pump.module.skd.bean.po.gen.ScheduleInstanceDtl;
import com.warm.pump.module.skd.service.IScheduleInstanceDtlService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 *  skd_instance_dtl
 *
 */
@Controller
@RequestMapping("/scheduleInstanceDtl")
public class ScheduleInstanceDtlController {
	@Autowired
	private IScheduleInstanceDtlService scheduleInstanceDtlService;
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("scheduleInstanceDtl:list")
	public OutJson list(Integer page, Integer limit, ScheduleInstanceDtl scheduleInstanceDtl){
		Map<String, Object> map = new HashMap<>();
		MyBeanUtils.copyBean2Map(map,scheduleInstanceDtl);

		if(StringUtils.isNotEmpty(scheduleInstanceDtl.getSidx())&&StringUtils.isNotEmpty(scheduleInstanceDtl.getOrder())){
			map.put("orderBy",scheduleInstanceDtl.getSidx()+" "+scheduleInstanceDtl.getOrder());
		}
       //查询列表数据
        PageBean pageBean = scheduleInstanceDtlService.getPageBeanByMap(map, page, limit);

		return OutJson.ok().put("page", pageBean);
	}


	/**
	 * 信息
	 */
	@ResponseBody
	@RequestMapping("/info/{id}")
	@RequiresPermissions("scheduleInstanceDtl:info")
	public OutJson info(@PathVariable("id") Long  id){
		ScheduleInstanceDtl scheduleInstanceDtl = scheduleInstanceDtlService.queryObject(id);
		
		return OutJson.ok().put("scheduleInstanceDtl", scheduleInstanceDtl);
	}


	/**
	 * 保存
	 */
	@ResponseBody
	@RequestMapping("/save")
	@RequiresPermissions("scheduleInstanceDtl:save")
	public OutJson save(@RequestBody ScheduleInstanceDtl scheduleInstanceDtl){
		scheduleInstanceDtlService.save(scheduleInstanceDtl);
		
		return OutJson.ok();
	}
	
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("scheduleInstanceDtl:update")
	public OutJson update(@RequestBody ScheduleInstanceDtl scheduleInstanceDtl){
		scheduleInstanceDtlService.update(scheduleInstanceDtl);
		
		return OutJson.ok();
	}
	
	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete")
	@RequiresPermissions("scheduleInstanceDtl:delete")
	public OutJson delete(@RequestBody Long [] ids){
		scheduleInstanceDtlService.deleteBatch(ids);
		
		return OutJson.ok();
	}
	
}
